package com.oktest.measure.item.home

import com.cali.common.kt.gone
import com.cali.common.kt.invisible
import com.cali.common.kt.visible
import com.chad.library.adapter.base.binder.QuickItemBinder
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.oktest.measure.R
import com.oktest.measure.entity.HomeTask
import com.oktest.measure.kt.setDrawable
import kotlinx.android.synthetic.main.item_home_page_task_notice.view.*

/**
 * @Author hhh
 * @Date 2020/9/17
 */

class HomeTaskBinder(val block:(HomeTask)->Unit) :QuickItemBinder<HomeTask>(){
    override fun getLayoutId(): Int {
        return R.layout.item_home_page_task_notice
    }

    override fun convert(holder: BaseViewHolder, data: HomeTask) {
        holder.itemView.apply {
            // 设置暂无任务
            if (data.id.isEmpty()) {
                group.invisible()
                tvEmpty.text = "暂无调试任务"
                tvEmpty.visible()
            } else {
                tvEmpty.invisible()
                group.visible()

                tvNoticeTitle.text = data.name
                tvNoticeTime.text = data.startupTime
                setOnClickListener {
                    block(data)
                }
                if (data.download) {
                    tvNoticeNew.gone()
                } else {
                    tvNoticeNew.visible()
                    tvNoticeNew.setDrawable(R.color.red,8f)
                }
            }
        }
    }
}